package com.bdqn.zhao.controller;


import com.bdqn.zhao.dao.SysDistrictsMapper;
import com.bdqn.zhao.pojo.SysDistricts;
import com.bdqn.zhao.service.SysDistrictsService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 地区 前端控制器
 * </p>
 *
 * @author zhangsan
 * @since 2023-04-24
 */
@RestController
@RequestMapping("/sysDistricts")
public class SysDistrictsController {

    @Autowired
    private SysDistrictsService sysDistrictsService;

    /**
     * 全查地址表数据
     *
     * @return
     */
    @RequestMapping("/selAll")
    public Map<String, Object> select() {
        List<SysDistricts> sysDistricts = sysDistrictsService.sysDistrictsAll();
        Map<String, Object> map = new HashMap<>();
        map.put("list", sysDistricts);
        return map;
    }

    /**
     * 编辑地址查询
     * @param id
     * @return
     */
    @GetMapping("/sel/{id}")
    public Map<String, Object> selectByi(@PathVariable int id) {
        SysDistricts sysDistricts = sysDistrictsService.selectByi(id);
        Map<String, Object> objectMap = new HashMap<>();
        objectMap.put("selByi", sysDistricts);
        return objectMap;
    }

    /**
     * 删除地址
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public Map<String,Object> del(@PathVariable int id){
        int del = sysDistrictsService.del(id);
        Map<String,Object> map=new HashMap<>();
        if (del>0) {
        map.put("stuats",true);
        }
        return map;
        }

    /**
     * 模糊查层级和名称
     * @param deep
     * @param name
     * @return
     */
        @GetMapping("/mohu/{pageNum}/{pageSize}")
        public Map<String,Object> fuzzy(@PathVariable Integer pageNum,
                                        @PathVariable Integer pageSize,Integer deep,String name){
            List<SysDistricts> fuzzy = sysDistrictsService.fuzzy(pageNum,pageSize,deep, name);
            Map<String,Object> map=new HashMap<>();
            map.put("mohu",fuzzy);
            return map;
        }

}
